package com.tiancheng.trade.settlement.service.settlement.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tiancheng.trade.commom.core.data.PageInfo;
import com.tiancheng.trade.commom.core.data.Result;
import com.tiancheng.trade.settlement.bo.MerchantBO;
import com.tiancheng.trade.settlement.enums.CostTypeEnum;
import com.tiancheng.trade.settlement.enums.OrderSourceEnum;
import com.tiancheng.trade.settlement.enums.PaymentChannelEnum;
import com.tiancheng.trade.settlement.exception.BusinessException;
import com.tiancheng.trade.settlement.feign.MerchantPaymentChannelService;
import com.tiancheng.trade.settlement.feign.OrderService;
import com.tiancheng.trade.settlement.mapper.settlement.*;
import com.tiancheng.trade.settlement.model.settlement.PaymentBill;
import com.tiancheng.trade.settlement.model.settlement.SettlementBankBillDetail;
import com.tiancheng.trade.settlement.model.settlement.SettlementBillResult;
import com.tiancheng.trade.settlement.model.settlement.SettlementRule;
import com.tiancheng.trade.settlement.service.settlement.IPaymentBillService;
import com.tiancheng.trade.settlement.service.settlement.ISettlementBankBillDetailService;
import com.tiancheng.trade.settlement.service.settlement.ISettlementBillResultService;
import com.tiancheng.trade.settlement.util.ExcelUtil;
import com.tiancheng.trade.settlement.vo.settlement.admin.*;
import com.tiancheng.trade.settlement.vo.settlement.admin.res.*;
import com.tiancheng.trade.settlement.vo.settlement.api.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.beans.PropertyDescriptor;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;

import static java.util.stream.Collectors.toList;

/**
 * 清分对账结果信息
 *
 * @author liuzhonghu
 */
@Slf4j
@Service
public class SettlementBillResultService implements ISettlementBillResultService {


    @Autowired
    private SettlementBillRepMapper billRepMapper;

    @Autowired
    private ISettlementBankBillDetailService bankBillDetailService;

    @Autowired
    private ISettlementBillResultService billResultService;

    @Autowired
    private IPaymentBillService paymentBillService;

    @Autowired
    private SettlementRuleMapper ruleMapper;

    @Autowired
    private MerchantPaymentChannelService merchantService;

    @Autowired
    private OrderService orderService;

    @Autowired
    private SettlementBillResultMapper billResultMapper;

    @Autowired
    private SettlementBillDetailMapper billDetailMapper;

    @Autowired
    private SettlementBillReconMapper billReconMapper;

    @Override
    public PageInfo<SettlementBillRepVO> getSettlementBillReport(SettlementBillQueryVO queryVO) {
        Page<SettlementBillDetailVO> page = new Page<>();
        page.setCurrent(queryVO.getCurrentPage());
        page.setSize(queryVO.getPageSize());
        IPage<SettlementBillRepVO> pageresult = billRepMapper.getSettlementBillReport(page, queryVO);
        PageInfo.Pagination pagination = new PageInfo.Pagination(queryVO.getCurrentPage(), queryVO.getPageSize(), page.getTotal());
        return new PageInfo<>(pageresult.getRecords(), pagination);
    }

    @Override
    public PageInfo<SettlementBillDetailVO> billDetailList(GetBillDetailVO queryVO) {
        Page<SettlementBillDetailVO> page = new Page<>();
        page.setCurrent(queryVO.getCurrentPage());
        page.setSize(queryVO.getPageSize());

        //先按银行清分日期查询,没数据按应清分日期
        IPage<SettlementBillDetailVO> pageresult = billDetailMapper.querySummaryView(page, queryVO);
//        if (CollectionUtils.isEmpty(pageresult.getRecords())) {
//            queryVO.setStartDate("");
//            queryVO.setEndDate("");
//            pageresult = billDetailMapper.queryPlatSummaryView(page, queryVO);
//        }

        PageInfo.Pagination pagination = new PageInfo.Pagination(queryVO.getCurrentPage(), queryVO.getPageSize(), page.getTotal());
        List<SettlementBillDetailVO> list = pageresult.getRecords();
        if (CollectionUtils.isNotEmpty(list)) {
            list.forEach(a -> {
                a.setCostTypeName(CostTypeEnum.getDesc(a.getCostType()));
                //银行有时,主订单,子订单,产品名称,付款账户名,收款账户名置空
//                if("3".equals(a.getStatus())){
//                    a.setOrderId("");
//                    a.setSubOrderId("");
//                    a.setProductName("");
//                    a.setPayAcctName("");
//                    a.setColAcctName("");
//                }
            });
        }
        return new PageInfo<>(list, pagination);
    }

    /**
     * 明细对账-导出
     *
     * @param billRepVO
     * @param request
     * @param response
     * @throws IOException
     */
    @Override
    public void exportSettlementBillDetail(GetBillDetailVO billRepVO, HttpServletRequest request, HttpServletResponse response) throws IOException {
        List<SettlementBillDetailVO> listExp = billDetailMapper.querySummaryView(billRepVO);
        List<Map<String, Object>> mapList = listDetailConvert(listExp);

        String fileName = "明细对账.xlsx";

        String[] title = {"清分日期", "费用类型", "主订单", "子订单", "商户号", "商户名称", "付款账户名", "收款账户名", "清分金额", "招行订单号", "清分金额", "订单日期", "核销日期", "对账日期", "差异", "差异原因", "对账次数"};
        HashMap<Integer, String> title1 = new HashMap<>();
        title1.put(1, "平台清分订单明细");
        title1.put(10, "银行清分汇总");
        title1.put(14, "对账处理");
        Workbook workbook = ExcelUtil.buildWorkbook2("明细对账", title1, title, mapList, getCellMergeDataDetail());
        ExcelUtil.exportExcle(request, response, workbook, fileName);
    }

    private List<CellMergeVO> getCellMergeDataDetail() {
        List<CellMergeVO> list = new ArrayList<>();
        CellMergeVO vo = new CellMergeVO();
        vo.setStartRow(0);
        vo.setStartCol(1);
        vo.setEndRow(0);
        vo.setEndCol(9);
        list.add(vo);
        vo = new CellMergeVO();
        vo.setStartRow(0);
        vo.setStartCol(10);
        vo.setEndRow(0);
        vo.setEndCol(13);
        list.add(vo);
        vo = new CellMergeVO();
        vo.setStartRow(0);
        vo.setStartCol(14);
        vo.setEndRow(0);
        vo.setEndCol(17);
        list.add(vo);
        return list;
    }

    /**
     * 清分汇总统计导出
     *
     * @param billRepVO
     * @param request
     * @param response
     * @throws IOException
     */
    public void exportSettlementBillReport(SettlementBillQueryVO billRepVO, HttpServletRequest request, HttpServletResponse response) throws IOException {
        List<SettlementBillRepVO> listExp = billRepMapper.getSettlementBillReport(billRepVO);
        List<Map<String, Object>> mapList = listConvert(listExp);

        String fileName = "清分汇总统计.xlsx";

        String[] title = {"清分日期", "平台商户总数", "平台子订单总数", "平台清分记账数", "平台清分总金额", "银行商户总数", "银行子订单总数", "银行清分记账数", "银行清分总金额", "差异商户数", "差异订单数", "差异记账数", "差异清分总金额", "对账日期"};
        HashMap<Integer, String> title1 = new HashMap<>();
        title1.put(1, "平台日汇总");
        title1.put(5, "银行日汇总");
        title1.put(9, "差异日汇总");
        Workbook workbook = ExcelUtil.buildWorkbook2("清分汇总统计", title1, title, mapList, getCellMergeData());
        ExcelUtil.exportExcle(request, response, workbook, fileName);
    }

    private List<CellMergeVO> getCellMergeData() {
        List<CellMergeVO> list = new ArrayList<>();
        CellMergeVO vo = new CellMergeVO();
        vo.setStartRow(0);
        vo.setStartCol(1);
        vo.setEndRow(0);
        vo.setEndCol(4);
        list.add(vo);
        vo = new CellMergeVO();
        vo.setStartRow(0);
        vo.setStartCol(5);
        vo.setEndRow(0);
        vo.setEndCol(8);
        list.add(vo);
        vo = new CellMergeVO();
        vo.setStartRow(0);
        vo.setStartCol(9);
        vo.setEndRow(0);
        vo.setEndCol(13);
        list.add(vo);
        return list;
    }

    /**
     * 清分汇总统计数据转换
     *
     * @param list
     * @return
     */
    private List<Map<String, Object>> listConvert(List<SettlementBillRepVO> list) {
        List<Map<String, Object>> list_map = new ArrayList<Map<String, Object>>();
        try {
            for (SettlementBillRepVO t : list) {
                Field[] fields = t.getClass().getDeclaredFields();
                Map<String, Object> m = new LinkedHashMap<String, Object>();
                for (Field field : fields) {
                    String keyName = field.getName();
                    PropertyDescriptor pd = new PropertyDescriptor(keyName, t.getClass());
                    Method getMethod = pd.getReadMethod();// 获得getter方法
                    Object o = getMethod.invoke(t);// 执行get方法返回一个Object
                    m.put(keyName, o);
                }
                list_map.add(m);
            }
            return list_map;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 汇总对账数据转换
     *
     * @param list
     * @return
     */
    private List<Map<String, Object>> listReconConvert(List<SettlementReconRepVO> list) {
        List<Map<String, Object>> list_map = new ArrayList<Map<String, Object>>();
        try {
            for (SettlementReconRepVO t : list) {
                Field[] fields = t.getClass().getDeclaredFields();
                Map<String, Object> m = new LinkedHashMap<String, Object>();
                for (Field field : fields) {
                    String keyName = field.getName();
                    PropertyDescriptor pd = new PropertyDescriptor(keyName, t.getClass());
                    Method getMethod = pd.getReadMethod();// 获得getter方法
                    Object o = getMethod.invoke(t);// 执行get方法返回一个Object
                    m.put(keyName, o);
                }
                list_map.add(m);
            }
            return list_map;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 明细对账数据转换
     *
     * @param list
     * @return
     */
    private List<Map<String, Object>> listDetailConvert(List<SettlementBillDetailVO> list) {
        List<Map<String, Object>> list_map = new ArrayList<Map<String, Object>>();
        try {
            for (SettlementBillDetailVO t : list) {
                Field[] fields = t.getClass().getDeclaredFields();
                Map<String, Object> m = new LinkedHashMap<String, Object>();
                for (Field field : fields) {
                    String keyName = field.getName();
                    PropertyDescriptor pd = new PropertyDescriptor(keyName, t.getClass());
                    Method getMethod = pd.getReadMethod();// 获得getter方法
                    Object o = getMethod.invoke(t);// 执行get方法返回一个Object
                    m.put(keyName, o);
                }
                list_map.add(m);
            }
            return list_map;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public SettlementBillDetail settlementBillDetailById(String id) {
        SettlementBillDetail billDetail = new SettlementBillDetail();
        SettlementBillResult billResult = new SettlementBillResult();
        billResult.setSubOrderId(id);
        billResult = billResultMapper.querySubOrderSettlementInfoBySubOrderId(billResult);
        if (null == billResult) {
            return billDetail;
        }

        if (null != billResult) {
            //清分对账信息
            billDetail.setBillResultDetail(billResult);
            //平台清分流水
            SettlementBillResult billResult1 = new SettlementBillResult();
            billResult1.setSubOrderId(billResult.getSubOrderId());
            List<SettlementBillResult> billResultList = billResultService.billResultList(billResult1);
            billDetail.setBillResultList(billResultList);

            //银行清分流水
            List<SettlementBankBillDetail> bankBillDetail = bankBillDetailService.queryBankBillDetailList(billResult.getSubOrderId());
            billDetail.setBankBillDetailList(bankBillDetail);

            //清分规则信息
            if (StringUtils.isNotEmpty(billResult.getClearRuleCode())) {
                QueryWrapper<SettlementRule> conditions = new QueryWrapper<SettlementRule>();
                conditions.eq("rule_code", billResult.getClearRuleCode());
                SettlementRule settlementRule = ruleMapper.selectOne(conditions);
                billDetail.setRule(settlementRule);
            }
            //商户信息
            if (StringUtils.isNotEmpty(billResult.getMerchantCode())) {
                Result<MerchantBO> result = merchantService.findMerchant(billResult.getMerchantCode());
                MerchantBO merchantBO = result.getData();
                billDetail.setMerchant(merchantBO);
            }
            //订单信息
            if (StringUtils.isNotEmpty(billResult.getSubOrderId())) {
                Result<SubOrderResVO> result = orderService.fetchQuerySubOrder(billResult.getSubOrderId());
                SubOrderResVO subOrderResVO = result.getData();
                billDetail.setOrder(subOrderResVO);

                String folwId = "";
                PaymentBill paymentBill = paymentBillService.getPaymentBill(folwId);

            }
        }
        return billDetail;
    }


    @Override
    public List<SettlementBillResult> billResultList(SettlementBillResult billResult) {
        QueryWrapper<SettlementBillResult> conditions = new QueryWrapper<SettlementBillResult>();
        if (StringUtils.isNotEmpty(billResult.getSubOrderId())) {
            conditions.eq("sub_order_id", billResult.getSubOrderId());
        }
        if (StringUtils.isNotEmpty(billResult.getSubMchId())) {
            conditions.eq("sub_mch_id", billResult.getSubMchId());
        }
        if (StringUtils.isNotEmpty(billResult.getMerchantCode())) {
            conditions.eq("merchant_code", billResult.getMerchantCode());
        }
        if (StringUtils.isNotEmpty(billResult.getOrderSource())) {
            conditions.eq("order_source", billResult.getOrderSource());
        }
        if (StringUtils.isNotEmpty(billResult.getColAcctName())) {
            conditions.eq("col_acc_name", billResult.getColAcctName());
        }
        List<SettlementBillResult> list = billResultMapper.selectList(conditions);
        return list;
    }

    @Override
    public SettlementBillResult billResultById(String id) {
        return billResultMapper.selectById(id);
    }

    @Override
    public List<SettlementBillResult> billResultByOrderId(String subOrderId) {
        QueryWrapper<SettlementBillResult> conditions = new QueryWrapper<SettlementBillResult>();
        conditions.eq("sub_order_id", subOrderId);
        List<SettlementBillResult> billResult = billResultMapper.selectList(conditions);
        return billResult;
    }

    private void setSuccessQueryParam(SuccessBillQueryVO queryVO) {
        String beginTime = " 00:00:00";
        String endTime = " 23:59:59";
        if (StringUtils.isNotEmpty(queryVO.getPayTimeBegin())) {
            queryVO.setPayTimeBegin(queryVO.getPayTimeBegin() + beginTime);
        }
        if (StringUtils.isNotEmpty(queryVO.getPayTimeEnd())) {
            queryVO.setPayTimeEnd(queryVO.getPayTimeEnd() + endTime);
        }
        if (StringUtils.isNotEmpty(queryVO.getVerifiedTimeBegin())) {
            queryVO.setVerifiedTimeBegin(queryVO.getVerifiedTimeBegin() + beginTime);
        }
        if (StringUtils.isNotEmpty(queryVO.getVerifiedTimeEnd())) {
            queryVO.setVerifiedTimeEnd(queryVO.getVerifiedTimeEnd() + endTime);
        }
        if (StringUtils.isNotEmpty(queryVO.getBankClearDateBegin())) {
            queryVO.setBankClearDateBegin(queryVO.getBankClearDateBegin() + beginTime);
        }
        if (StringUtils.isNotEmpty(queryVO.getBankClearDateEnd())) {
            queryVO.setBankClearDateEnd(queryVO.getBankClearDateEnd() + endTime);
        }
        if (StringUtils.isNotEmpty(queryVO.getShouldBillDateBegin())) {
            queryVO.setShouldBillDateBegin(queryVO.getShouldBillDateBegin() + beginTime);
        }
        if (StringUtils.isNotEmpty(queryVO.getShouldBillDateEnd())) {
            queryVO.setShouldBillDateEnd(queryVO.getShouldBillDateEnd() + endTime);
        }
    }

    @Override
    public PageInfo<SuccessBillResVO> querySuccessBill(SuccessBillQueryVO queryVO) throws BusinessException {
        Page<SuccessBillResVO> page = new Page<>();
        page.setCurrent(queryVO.getCurrentPage());
        page.setSize(queryVO.getPageSize());
        setSuccessQueryParam(queryVO);
        IPage<SuccessBillResVO> pageresult = billResultMapper.querySuccessBillView(page, queryVO);
        PageInfo.Pagination pagination = new PageInfo.Pagination(queryVO.getCurrentPage(), queryVO.getPageSize(), page.getTotal());
        List<SuccessBillResVO> vos = pageresult.getRecords();
//        List<String> subOrderIds = pageresult.getRecords().stream().map(SuccessBillResVO::getSubOrderId).collect(Collectors.toList());
//        List<SuccessBankResVO> successBank = null;
//        if (CollectionUtils.isNotEmpty(subOrderIds)) {
//            successBank = billResultMapper.querySuccessBankView(subOrderIds, queryVO);
//        }

        for (SuccessBillResVO vo : vos) {
//            if (CollectionUtils.isNotEmpty(successBank)) {
//                List<SuccessBankResVO> bankList = successBank.stream().filter(x -> x.getSubOrderId().equals(vo.getSubOrderId())).collect(Collectors.toList());
//                Integer backAmount = bankList.stream().collect(Collectors.summingInt(SuccessBankResVO::getClearAmount));
//                Integer amount = Integer.valueOf(vo.getClearAmount()) - backAmount;
//                vo.setErrorAmount(amount.toString());
//            }
            vo.setOrderSourceCN(OrderSourceEnum.getDesc(vo.getOrderSource()));
            vo.setPayChannelCodeCN(PaymentChannelEnum.getDesc(vo.getPayChannelCode()));
        }
        pageresult.setRecords(vos);
        return new PageInfo<>(pageresult.getRecords(), pagination);
    }

    @Override
    public PageInfo<SettlementReconRepVO> getSettlementReconReport(SettlementReconQueryVO queryVO) throws BusinessException {
        Page<SuccessBillResVO> page = new Page<>();
        page.setCurrent(queryVO.getCurrentPage());
        page.setSize(queryVO.getPageSize());
        IPage<SettlementReconRepVO> pageresult = billReconMapper.getSettlementReconReport(page, queryVO);
        List<SettlementReconRepVO> list = pageresult.getRecords();
        //取两者子订单差集
//        list.forEach(a -> {
//            SettlementReconQueryVO reconQueryVO = new SettlementReconQueryVO();
//            reconQueryVO.setSubMchId(a.getSubMchId());
//            reconQueryVO.setClearDate(a.getClearDate());
//            List<String> bankList = billReconMapper.getBankSubOrderId(reconQueryVO);
//            List<String> resultList = billReconMapper.getResultSubOrderId(reconQueryVO);
//            List<String> listAll = new ArrayList<String>();
//            listAll.addAll(bankList.stream().filter(item -> !resultList.contains(item)).collect(toList()));
//            listAll.addAll(resultList.stream().filter(item -> !bankList.contains(item)).collect(toList()));
//            a.setDiffSubOrderCount(listAll.size());
//        });

        PageInfo.Pagination pagination = new PageInfo.Pagination(queryVO.getCurrentPage(), queryVO.getPageSize(), page.getTotal());
        return new PageInfo<>(pageresult.getRecords(), pagination);
    }

    /**
     * 汇总对账导出
     *
     * @param queryVO
     * @param request
     * @param response
     * @throws IOException
     */
    @Override
    public void exportSettlementReconReport(SettlementReconQueryVO queryVO, HttpServletRequest request, HttpServletResponse response) throws IOException {
        List<SettlementReconRepVO> listExp = billReconMapper.getSettlementReconReport(queryVO);
        List<Map<String, Object>> mapList = listReconConvert(listExp);
        String fileName = "汇总对账.xlsx";
        String[] title = {"清分日期", "商户号", "付款账户名", "付款账号", "收款账户名", "收款账号", "清分金额", "清分记账数", "清分执行时间", "清分金额", "清分记账数", "对账日期", "差异", "差异笔数", "已处理笔数"};
        HashMap<Integer, String> title1 = new HashMap<>();
        title1.put(1, "平台清分汇总");
        title1.put(9, "银行清分汇总");
        title1.put(12, "差异汇总");
        Workbook workbook = ExcelUtil.buildWorkbook2("汇总对账", title1, title, mapList, getCellMergeDataRecon());
        ExcelUtil.exportExcle(request, response, workbook, fileName);
    }

    private List<CellMergeVO> getCellMergeDataRecon() {
        List<CellMergeVO> list = new ArrayList<>();
        CellMergeVO vo = new CellMergeVO();
        vo.setStartRow(0);
        vo.setStartCol(1);
        vo.setEndRow(0);
        vo.setEndCol(8);
        list.add(vo);
        vo = new CellMergeVO();
        vo.setStartRow(0);
        vo.setStartCol(9);
        vo.setEndRow(0);
        vo.setEndCol(11);
        list.add(vo);
        vo = new CellMergeVO();
        vo.setStartRow(0);
        vo.setStartCol(12);
        vo.setEndRow(0);
        vo.setEndCol(15);
        list.add(vo);
        return list;
    }

//    @Override
//    public PageInfo<SettlementExceptionRepVO> getSettlementException(SettlementExceptionQueryVO queryVO) throws BusinessException {
//        Page<SettlementExceptionRepVO> page = new Page<>();
//        page.setCurrent(queryVO.getCurrentPage());
//        page.setSize(queryVO.getPageSize());
//        IPage<SettlementExceptionRepVO> pageresult = billExceptMapper.getSettlementException(page, queryVO);
//        PageInfo.Pagination pagination = new PageInfo.Pagination(queryVO.getCurrentPage(), queryVO.getPageSize(), page.getTotal());
//        return new PageInfo<>(pageresult.getRecords(), pagination);
//    }
//
//    @Override
//    public void exportSettlementException(SettlementExceptionQueryVO queryVO, HttpServletRequest request, HttpServletResponse response) throws IOException {
//
//    }

    /**
     * 功能描述: 成功对账导出
     *
     * @param:
     * @return:
     * @auther: LiuDong
     * @date: 13:57 2024/4/30
     */
    @Override
    public void successBillexport(SuccessBillQueryVO queryVO, HttpServletRequest request, HttpServletResponse response) throws BusinessException, IOException {
        setSuccessQueryParam(queryVO);
        List<SuccessBillResVO> pageresult = billResultMapper.successBillExport(queryVO);
        List<Map<String, Object>> mapList = successBillConvert(pageresult);
        String fileName = "成功对账单.xlsx";
        String[] title = {"子订单号", "主订单号", "商品名称", "商品编号", "业务场景", "商户名称", "商户编码", "清分渠道", "清分金额", "异常金额", "异常原因", "交易时间", "核销时间", "清分时间", "对账时间"};
        Workbook workbook = ExcelUtil.buildWorkbook("招行清分汇总", title, mapList);
        ExcelUtil.exportExcle(request, response, workbook, fileName);
    }

    @Override
    public PageInfo<AbnormalDataResVO> queryAbnormalDataList(AbnormalDataQueryVO queryVO) throws BusinessException {
        Page<AbnormalDataResVO> page = new Page<>();
        page.setCurrent(queryVO.getCurrentPage());
        page.setSize(queryVO.getPageSize());

        IPage<AbnormalDataResVO> pageresult = billResultMapper.queryAbnormalDataList(page, queryVO);
        PageInfo.Pagination pagination = new PageInfo.Pagination(queryVO.getCurrentPage(), queryVO.getPageSize(), page.getTotal());
        List<AbnormalDataResVO> list = pageresult.getRecords();
        list.forEach(a -> {
            a.setErrorAmount(a.getClearAmount() - a.getBankClearAmount());
            //3-银行有我方无  王欣确认此种状态,页面不需要显示下列值
            if (StringUtils.isNotEmpty(a.getStatus()) && a.getStatus().equals("3")) {
                a.setOrderId("");
                a.setSubOrderId("");
                a.setProductName("");
                a.setClearAmount(0);
                a.setClearCount(0);
            }
            if (StringUtils.isNotEmpty(a.getStatus()) && a.getStatus().equals("2")) {
                a.setBankClearAmount(0);
                a.setBankClearCount(0);
            }
        });
        return new PageInfo<>(list, pagination);
    }

    /**
     * 查询需生成对账函的商户信息
     *
     * @param queryVO
     * @return
     */
    @Override
    public List<StatementProductResVO> queryStatementAccount(StatementAccountCreateVO queryVO) {
        return billResultMapper.queryStatementAccount(queryVO);
    }

    /**
     * 查询需生成对账函的产品信息
     *
     * @param queryVO
     * @return
     */
    @Override
    public List<StatementProductResVO> queryStatementProduct(StatementAccountCreateVO queryVO) {
        return billResultMapper.queryStatementProduct(queryVO);
    }

    /**
     * 按id查询对账结果
     *
     * @param ids
     * @return
     */
    @Override
    public List<AbnormalDataResVO> getResultByIds(List<String> ids) {
        return billResultMapper.getResultByIds(ids);
    }


    /**
     * 数据转换
     *
     * @param list
     * @return
     */
    private List<Map<String, Object>> successBillConvert(List<SuccessBillResVO> list) {
        List<Map<String, Object>> list_map = new ArrayList<>();
        try {
            for (SuccessBillResVO t : list) {
                Field[] fields = t.getClass().getDeclaredFields();
                Map<String, Object> m = new LinkedHashMap<>();
                for (Field field : fields) {
                    String keyName = field.getName();
                    PropertyDescriptor pd = new PropertyDescriptor(keyName, t.getClass());
                    Method getMethod = pd.getReadMethod();// 获得getter方法
                    Object o = getMethod.invoke(t);// 执行get方法返回一个Object
                    m.put(keyName, o);
                }
                list_map.add(m);
            }
            return list_map;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        List<String> list1 = new ArrayList<String>();
        list1.add("2");
        list1.add("3");

        List<String> list2 = new ArrayList<String>();
        list2.add("2");
        list2.add("3");

        // 差集 (list1 - list2)
        List<String> reduce1 = list1.stream().filter(item -> !list2.contains(item)).collect(toList());
        System.out.println("---差集 reduce1 (list1 - list2)---");
        reduce1.parallelStream().forEach(System.out::println);

        // 差集 (list1 - list2)
        List<String> reduce2 = list2.stream().filter(item -> !list1.contains(item)).collect(toList());
        System.out.println("---差集 reduce1 (list1 - list2)---");
        reduce2.parallelStream().forEach(System.out::println);

    }

}
